﻿using System;
using System.Collections.Generic;

namespace Com.OpenCode.Framework.Core
{
    /// <summary>
    ///     Doozer管理器。
    /// </summary>
    public class Doozers
    {
        private List<IDoozer> _Doozers = new List<IDoozer>();

        public Doozers()
        {
            _Doozers.Add(new ClassDoozer());
            _Doozers.Add(new IconDoozer());
            _Doozers.Add(new ConditionDoozer());
        }

        public int Count
        {
            get { return _Doozers.Count; }
        }

        public void Add(IDoozer doozer)
        {
            if (doozer == null)
            {
                throw new Exception("添加的Doozer不能为空。");
            }
            if (Contain(doozer.Name))
            {
                Remove(doozer.Name);
            }
            _Doozers.Add(doozer);
        }

        public void Remove(string doozerName)
        {
            _Doozers.RemoveAll(p => p.Name == doozerName);
        }

        public bool Contain(string doozerName)
        {
            return _Doozers.Find(p => p.Name == doozerName) != null;
        }

        public IDoozer Get(string doozerName)
        {
            return _Doozers.Find(p => p.Name == doozerName);
        }

        public IDoozer Get(int index)
        {
            return _Doozers[index];
        }
    }
}